package com.chinaunicom.smartcity.dao;

import com.chinaunicom.smartcity.dto.Demo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by wyt on 2019/7/30.
 */
public interface DemoRepository extends JpaRepository<Demo, String>, JpaSpecificationExecutor<Demo> {
    /**
     * 自定义jpa的写法，传属性
     * @return List<Demo>
     */
    Demo getById(String id);

    /**
     * 自定义级联查询jpa的写法，传属性
     * @return List<Demo>
     */
 //   long countByEmpEmpId(String empId);

    /**
     * 自定义sql的写法，传属性
     * @return List<Demo>
     */
    @Query(value = "SELECT * FROM Demo where sts = ? ORDER BY udate DESC limit 0,10", nativeQuery = true)
    List<Demo> selectDemoList(String sts);

    /**
     * 自定义sql的写法2,传对象
     * @return List<Demo>
     */
    @Query(value = "SELECT * FROM Demo where sts = :sts ORDER BY udate DESC limit 0,10", nativeQuery = true)
    List<Demo> selectDemoList2(Demo demo);
}
